<template>
     <div>
        <div class="add-user-box" v-if='isModel&&isMainWin'>
            <div class="addUserCont">
                <div class="adduserHead flex flex-align-center">
                    <p class="flex-1">新增会员</p>
                    <img src="@/assets/img/business/business-close.png" alt="" @click="closeModelFun">
                </div>
                <div class="adduserwinCont">
                    <div class="radioBox flex flex-align-center">
                        <p>开户类型</p>
                        <el-radio v-model="radio" :label="item.member_type" v-for='(item,index) in addWinData.member' :key='index'>{{item.name}}</el-radio>
                    </div>
                    <p class="add-tips">{{name}}{{Cont}}</p>
                    <div class="inputBox flex flex-align-center">
                        <p>用户名</p>
                        <input type="text" v-model.trim='userName'>
                        <div class="flex flex-align-center" v-if="isTips != '' ">
                            <img src="@/assets/img/user-center/tx-jysb.png" alt="">
                            <p style="font-size:0.1rem">{{isTips}}</p>
                        </div>
                    </div>
                    <p class="timeLin">软件使用时间 <span>{{addWinData.use_time}}</span></p>
                    <p class="pwdLin">密码（预设） <span>{{addWinData.default_password}}</span></p>
                    <div class="groupBtn flex flex-align-center">
                         <div class="addBtn flex flex-align-center flex-pack-center" @click="addUserQuerenFun"><p>新增</p></div>
                         <div class="quxiaoBtn flex flex-align-center flex-pack-center" @click="onQuxiaoFun"><p>取消</p></div>
                    </div>
                </div>
            </div>
        </div>
        <CopyWin :isWin='iscopyWin' v-on:close="closeChildWin" :child='childData'></CopyWin>
     </div>
</template>
<script>
import CopyWin from './copyWin.vue'
import https from '@/public/https'
export default {
    components: {
        CopyWin,
    },
    data () {
        return {
            radio:null,
            iscopyWin:false,
            isMainWin:true,
            Cont:'',
            isTips:'',
            userName:'',
            childData:{},
            name:'',
        }
    },
    watch: {
       radio(news,old){
           for(var i in this.addWinData.member){
               if(news == this.addWinData.member[i].member_type){
                    this.Cont = this.addWinData.member[i].remaining.replace('(','').replace(')','');
                    this.name = this.addWinData.member[i].name;
               }
           }
       } 
    },
    props: {
        isModel:{
            type: Boolean,
            default: false 
        },
        addWinData:{
            type:Object,
            default: {}
        }
    },
    methods: {
        closeModelFun(){
             this.$emit('close');
        },
        addUserQuerenFun(){ //新增
            let uid = this.$store.state.userInfo.id;
            if(this.radio != null){
                if(this.userName){
                   https.post('user/postAddUser',{uid:uid,member_type:this.radio,user_name:this.userName})
                    .then(data =>{
                        if(data.status == 1){
                            this.childData = data.data;
                            this.iscopyWin = true;
                            this.postObtainUserInfoByUid();
                            this.userName='';
                            this.$emit('close');
                        }else{
                            this.isTips = data.message;
                        }
                    })
                }else{
                    this.$toast({massge:'请输入用户名'});
                }
            }else{
                 this.$toast({massge:'请选择开户类型'});
            }
        },

        // 查询用户详情
        postObtainUserInfoByUid(){
             this.https('User/postObtainUserInfoByUid',{},'post')
             .then(data => {
                    data.use_end_time = this.format(data.use_end_time,1);
                    this.$store.commit('setUserInfo',data);
             });
        },
        onQuxiaoFun(){ //取消
             this.$emit('close');
        },
        closeChildWin(){
            this.iscopyWin = false;
        }
    }
}
</script>
<style lang="less" scoped>
@import url(../../../assets/css/chatroom/adduserwin.less);
</style>


